<?php
/**
 * Search.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/6/11
 * Time: 15:08
 */
namespace app\api\open\commodity;

use app\api\model\GoodsModel;
use app\api\model\GoodsSpecModel;
use app\api\open\Base;
use think\Hook;

class Search extends Base
{
    protected $where = [];

    public function __construct($param = [])
    {
        parent::__construct($param);
        if(!empty($this->params['keywords']))
        {
            $this->where['title'] = ['like','%'.$this->params['keywords'].'%'];
        }
    }

    /**
     * @param array $param
     * @return array|false|null|\PDOStatement|string|\think\Model
     * @throws \Exception
     */
    public function index($param=[])
    {
        // 获取商品列表
        return GoodsModel::getInstance()->getList($this->where,[
            'field'=> 'id,title,images'
        ]);
    }
}